* Load dataset
use "replication data - main.dta", clear

log using "table 1-3.txt", text replace
log off

preserve
keep if year >1990		// drop years before 1990

gen Islamist_attk = ln_Islamattk1yr
gen nonIslamist_attk = ln_nonIslamattk1yr

gen Islamist_terror = ln_Islamkill1yr
gen nonIslamist_terror = ln_nonIslamkill1yr 


local main 			"(c.Islamist_terror c.nonIslamist_terror)##i.islamic_opposition c.problems"
local inter_west	"(c.Islamist_terror c.nonIslamist_terror)##i.islamic_opposition##i.western"
local inter_911		"(c.Islamist_terror c.nonIslamist_terror)##i.islamic_opposition##i.post911"
local inter_igo		"(c.Islamist_terror c.nonIslamist_terror)##i.islamic_opposition##i.igo"
local main_attk		"(c.Islamist_attk   c.nonIslamist_attk)##i.islamic_opposition"
local main_D		"(i.Islamist_terror_D i.nonIslamist_terror_D)##i.islamic_opposition"

local controls 		"c.problems muslim00 c.polity2 polity2_change ln_mortality firstmpany transitional_election postconflict pre_election_violence ln_oil lln_total_trade col_any postcoup ln_gdptotal legelec"



************************
* Analyses for TABLE 1 *
************************

* OLS: All countries
reg acceptable `main' `controls', cl(ccode)
est store all_tb1

* OLS-FE: All countries
xtreg acceptable `main' `controls', cl(ccode) fe
est store FE_tb1

* OLS: West vs Rest
reg acceptable `main' `controls' if western==1 , cl(ccode)
est store west_tb1

reg acceptable `main' `controls' if western==0 , cl(ccode)
est store nonwest_tb1

reg acceptable `inter_west' `controls' , cl(ccode)
est store interax_west_tb1

* OLS: Pre vs Post-911
reg acceptable `main' `controls' if post911==0 , cl(ccode)
est store pre911_tb1

reg acceptable `main' `controls' if post911==1 , cl(ccode)
est store post911_tb1

reg acceptable `inter_911' `controls', cl(ccode)
est store interax_911_tb1

log on
***********
* TABLE 1 *
***********

esttab all_tb1 FE_tb1 nonwest_tb1 west_tb1 pre911_tb1 post911_tb1, b(3) se(3) compress mtitles noomit nobase star(* 0.1 ** 0.05) 	///
	stats(N r2)	keep(*sla* problems) varwidth(50)				///
	order(problems 1.islamic_opposition Islamist_terror nonIslamist_terror	///
	1.islamic_opposition#c.Islamist_terror 				///
	1.islamic_opposition#c.nonIslamist_terror)			///
	///
	coeflabels(1.islamic_opposition "Islamist Opposition Party"		///
	Islamist_terror "Islamist Terrorism"				///
	nonIslamist_terror "Non-Islamist Terrorism"			///
	1.islamic_opposition#c.Islamist_terror "Islamist Terrorism * Islamist Opposition"	///
	1.islamic_opposition#c.nonIslamist_terror "Non-Islamist Terrorism * Islamist Opposition"	///
	problems "Problems")
	 
log off	
	
************************
* Analyses for TABLE 2 *
************************
	
* Logit estimator
logit acceptable `main' `controls' , cl(ccode)
est store lgt_all_tb2

* Alternative problem definition (NELDA-index)
gen NLD_problem_score = NLD_opposition_prevented + NLD_govt_harass

local controls_nelda	"c.NLD_problem_score muslim00 c.polity2 polity2_change ln_mortality firstmpany transitional_election postconflict pre_election_violence ln_oil lln_total_trade col_any i.region"
local controls_nelda	"c.NLD_problem_score muslim00 c.polity2 polity2_change ln_mortality firstmpany transitional_election postconflict pre_election_violence ln_oil lln_total_trade col_any postcoup ln_gdptotal legelec"

reg acceptable `main' `controls_nelda', cl(ccode)
est store altvdef_tb2

* Alternative terrorism definition (in the last 5 years)
replace Islamist_terror = ln_Islamkill5yr
replace nonIslamist_terror = ln_nonIslamkill5yr

reg acceptable `main'	///
	`controls' , cl(ccode)
est store terror5_tb2

replace Islamist_terror = ln_Islamkill1yr
replace nonIslamist_terror = ln_nonIslamkill1yr

log on
***********
* TABLE 2 *
***********

esttab lgt_all_tb2 altvdef_tb2 terror5_tb2, b(3) se(3) compress mtitles noomit nobase star(* 0.1 ** 0.05) 	///
	stats(N ll r2) 	///
	keep(*sla* problems *NLD*) varwidth(50)					///
	order(problems NLD_problem_score 1.islamic_opposition 	///
	Islamist_terror nonIslamist_terror						///
	1.islamic_opposition#c.Islamist_terror 					///
	1.islamic_opposition#c.nonIslamist_terror)				///
	///
	coeflabels(1.islamic_opposition "Islamist Opposition Party"		///
	Islamist_terror "Islamist Terrorism"				///
	nonIslamist_terror "Non-Islamist Terrorism"			///
	1.islamic_opposition#c.Islamist_terror "Islamist Terrorism * Islamist Opposition"	///
	1.islamic_opposition#c.nonIslamist_terror "Non-Islamist Terrorism * Islamist Opposition"	///
	problems "Problems"					///
	NLD_index	"NELDA Index of Problems")

log off

************************
* Analyses for TABLE 3 *
************************

* All monitors
reg acceptable `main' `controls' `extra', cl(ccode)
est store r_all`version'

gen sample = e(sample)
local all_full1 = _b[c.Islamist_terror#1.islamic_opposition]
local all_full2 = _b[c.nonIslamist_terror#1.islamic_opposition]

reg acceptable `main' if sample ==1, cl(ccode)
est store r_all`version'2

local all_none1 = _b[c.Islamist_terror#1.islamic_opposition]
local all_none2 = _b[c.nonIslamist_terror#1.islamic_opposition]


* Fixed effects
drop sample
xtreg acceptable `main' `controls' `extra', cl(ccode) fe
est store xtr_all`version'

gen sample = e(sample)
local xtall_full1 = _b[c.Islamist_terror#1.islamic_opposition]
local xtall_full2 = _b[c.nonIslamist_terror#1.islamic_opposition]

xtreg acceptable `main' if sample ==1, cl(ccode) fe
est store xtr_all`version'2

local xtall_none1 = _b[c.Islamist_terror#1.islamic_opposition]
local xtall_none2 = _b[c.nonIslamist_terror#1.islamic_opposition]


* Western monitors
drop sample
reg acceptable `main' `controls' `extra' if western ==1, cl(ccode)
est store r_west`version'

gen sample = e(sample)
local west_full1 = _b[c.Islamist_terror#1.islamic_opposition]
local west_full2 = _b[c.nonIslamist_terror#1.islamic_opposition]

reg acceptable `main' if western ==1 & sample ==1, cl(ccode)
est store r_west`version'2

local west_none1 = _b[c.Islamist_terror#1.islamic_opposition]
local west_none2 = _b[c.nonIslamist_terror#1.islamic_opposition]


* Non-Western monitors
drop sample
reg acceptable `main' `controls' `extra' if western ==0, cl(ccode)
est store r_rest`version'

gen sample = e(sample)
local rest_full1 = _b[c.Islamist_terror#1.islamic_opposition]
local rest_full2 = _b[c.nonIslamist_terror#1.islamic_opposition]

reg acceptable `main' if western ==0 & sample ==1, cl(ccode)
est store r_rest`version'2

local rest_none1 = _b[c.Islamist_terror#1.islamic_opposition]
local rest_none2 = _b[c.nonIslamist_terror#1.islamic_opposition]


* Post-911
drop sample
reg acceptable `main' `controls' `extra' if post911 ==1, cl(ccode)
est store r_post`version'

gen sample = e(sample)
local post_full1 = _b[c.Islamist_terror#1.islamic_opposition]
local post_full2 = _b[c.nonIslamist_terror#1.islamic_opposition]

reg acceptable `main' if post911==1 & sample ==1, cl(ccode)
est store r_post`version'2

local post_none1 = _b[c.Islamist_terror#1.islamic_opposition]
local post_none2 = _b[c.nonIslamist_terror#1.islamic_opposition]


* Pre-911
drop sample
reg acceptable `main' `controls' `extra' if post911 ==0, cl(ccode)
est store r_pre`version'

gen sample = e(sample)
local pre_full1 = _b[c.Islamist_terror#1.islamic_opposition]
local pre_full2 = _b[c.nonIslamist_terror#1.islamic_opposition]

reg acceptable `main' if post911 ==0 & sample ==1, cl(ccode)
est store r_pre`version'2

local pre_none1 = _b[c.Islamist_terror#1.islamic_opposition]
local pre_none2 = _b[c.nonIslamist_terror#1.islamic_opposition]

log on

***********
* TABLE 3 *
***********
 
display abs(`all_full1' / ( `all_none1' - `all_full1' ))

display abs(`xtall_full1' / ( `xtall_none1' - `xtall_full1' ))

display abs(`west_full1' / ( `west_none1' - `west_full1' ))

display abs(`post_full1' / ( `post_none1' - `post_full1' ))

log close

restore
